/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024.
 * Description: RTOS self-developed code for skbuff.c
 * Author: Wang Haitao
 * Create: 2023/9/14
 */

#ifdef CONFIG_RTOS_NET_SKB_PRIV_COPY
#define MAX_PRIV_LEN (4096)
static int skb_priv_len __read_mostly = 128;

static int __init get_skb_priv_len(char *arg)
{
	get_option(&arg, &skb_priv_len);
	if (skb_priv_len > MAX_PRIV_LEN)
		skb_priv_len = MAX_PRIV_LEN;
	printk(KERN_INFO "skbuff priv len is %d.\n", skb_priv_len);
	return 0;
}

early_param("skb_priv", get_skb_priv_len);

static void set_skb_priv_date(void *skb_start, struct kmem_cache *type)
{
	int skip;
	int len;

	if (skb_priv_len <= 0)
		return;

	if (skbuff_fclone_cache == type) {
		skip = (2 * sizeof(struct sk_buff)) + sizeof(atomic_t);
		len = 2 * skb_priv_len;
	} else {
		skip = sizeof(struct sk_buff);
		len = skb_priv_len;
	}
	memset(skb_start + skip, 0, len);
}
#endif